﻿using System.Collections.Generic;
using ORM.Business.Feedbacks;
using ORM.Business.Interfaces;
using ORM.Business.Models.Entities;
using ORM.Common.Caching;

namespace ORM.Business.Models.Caching
{
    public class DeviceCollection : CacheCollection<Device>
    {
         private IDeviceRepository _repository;

        public DeviceCollection(IDeviceRepository repository)
        {
            _repository = repository;
        }

        #region Overrides of CacheCollection<Device>

        public override void Execute()
        {
            Feedback<IList<Device>> feedback = _repository.GetAllDevice();
           
            IsPopulated = feedback.Success;
            if (feedback.Success)
            {
                Clear();
                AddRange(feedback.Data);
            }
        }

        #endregion
    }
}